package com.atguigu.vodservice.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vodservice.service.VideoService;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author alan
 */
@Api(tags = "视频资源控制器")
@CrossOrigin
@RestController
@RequestMapping("/vod/video")
public class VodController {

    @Resource
    private VideoService videoService;

    @ApiOperation("通过Ids删除多个")
    @PostMapping("/delete")
    public R deleteVideoById(@RequestBody List<String> ids) {
        if (videoService.deleteVideoByIds(ids)) {
            return R.ok("删除视频成功");
        }
        return R.error("删除视频失败");
    }

    @ApiOperation("通过Id删除单个")
    @PostMapping("/deleteOne/{id}")
    public R deleteVideoById(@PathVariable("id") String id) {
        if (videoService.deleteVideoById(id)) {
            return R.ok("删除视频成功");
        }
        return R.error("删除视频失败");
    }

    @ApiOperation("视频上传")
    @PostMapping("/upload")
    public R uploadVideo(MultipartFile file) {
        String videoId = videoService.uploadVideo(file);
        if (StringUtils.isNotEmpty(videoId)) {
            return R.ok().data("id", videoId);
        }
        return R.error();
    }

    @ApiOperation("通过Id获取视频信息")
    @PostMapping("/info/{id}")
    public R getInfoById(@PathVariable("id") String id) {
        return null;
    }

}
